package servlet;

import Hbase.Add;
import pojo.ST;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

@WebServlet("/AddServlet")
public class AddServlet extends HttpServlet {
    public void init(HttpServletRequest req, HttpServletResponse resp) throws UnsupportedEncodingException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        resp.setCharacterEncoding("utf-8");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        init(req,resp);
        String ID=req.getParameter("id");
        String name=req.getParameter("name");
        String date=req.getParameter("date");
        String number=req.getParameter("number");
        String semester=req.getParameter("semester");
        String status;
        String A="8";
        if(semester.compareTo(A)>=0){
            status="A";
        }else{
            status="L";
        }
        ST studentTable=new ST();
        studentTable.setStudentID(ID);
        studentTable.setStudentName(name);
        studentTable.setStudentDate(date);
        studentTable.setStudentNumber(number);
        studentTable.setStudentSemester(semester);
        studentTable.setStudentStatus(status);

        Add add=new Add(studentTable);
        RequestDispatcher dispatchToLogin = req.getRequestDispatcher("/add.jsp");
        dispatchToLogin.forward(req, resp);

//        ("Init.jsp");

    }
}
